from selenium.webdriver.support.select import Select
from selenium.webdriver.support.wait import WebDriverWait
from selenium import webdriver
import time
from selenium.webdriver.chrome.options import Options

# 声明浏览器，打开远程调试
Chrome_options = Options()
Chrome_options.add_experimental_option('debuggerAddress', "127.0.0.1:9222")
browser = webdriver.Chrome(options=Chrome_options)

# 找到html文件并打开
Path_name = 'D:/PythonWorkspace/python100/Day52/selenium.html'
browser.get(Path_name)

# 查找元素并操作
User_name = browser.find_element_by_css_selector('div#signup [name="username"]').send_keys('rabbit')
time.sleep(2)
Pass_word = browser.find_element_by_css_selector('div#signup [name="password"]').send_keys('love')
time.sleep(2)
Remember = browser.find_element_by_css_selector('div#signup [name="remeber"]').click()
time.sleep(2)
Multi = browser.find_element_by_css_selector('div#signup [name="multi_login"]').click()
time.sleep(2)
City_select = Select(browser.find_element_by_name('city'))
City_select.select_by_value('sz')
time.sleep(2)
Submit_button = browser.find_element_by_css_selector('div#signup form').submit()

# 显式等待
success = WebDriverWait(browser, 10, 1).until(
    lambda x: x.find_element_by_css_selector("div#signup p").text == "注册成功")

# 关闭浏览器
browser.quit()